import javax.swing.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class text1{
    public static void main(String[] args) {
        // 登录窗口
        JFrame loginFrame = new JFrame("登录");
        loginFrame.setSize(300, 200);
        loginFrame.setLayout(new BoxLayout(loginFrame.getContentPane(), BoxLayout.Y_AXIS));

        JLabel userLabel = new JLabel("用户名:");
        JTextField userText = new JTextField(20);

        JLabel passLabel = new JLabel("密码:");
        JPasswordField passText = new JPasswordField(20);

        JButton submitButton = new JButton("登录");
        //123

        // 组件添加到窗口
        loginFrame.add(userLabel);
        loginFrame.add(userText);
        loginFrame.add(passLabel);
        loginFrame.add(passText);
        loginFrame.add(submitButton);

        // 按钮事件
        submitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                String username = userText.getText();
                String password = new String(passText.getPassword());

                if ("admin".equals(username) && "123456".equals(password)) {
                    System.out.println("欢迎回来，" + username + "!");

                    // 创建成功页面
                    JFrame successFrame = new JFrame("登录成功");
                    successFrame.setSize(200, 100);
                    JLabel label = new JLabel("666", SwingConstants.CENTER);
                    successFrame.add(label);
                    successFrame.setVisible(true);

                    loginFrame.dispose(); // 关闭登录窗口
                }
            }
        });

        loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        loginFrame.setVisible(true);
    }
}
